<?php

namespace iBrand\Shop\Core\Models;

use Illuminate\Database\Eloquent\Model;

class ClerkBalanceOrder extends Model
{
	protected $guarded = ['id'];

	public function __construct(array $attributes = [])
	{
		parent::__construct($attributes);

		$prefix = config('ibrand.app.database.prefix', 'ibrand_');

		$this->setTable($prefix . 'o2o_clerk_balance_order');
	}

	public function clerk()
	{
		return $this->hasOne(Clerk::class, 'id', 'clerk_id');
	}

	public function shops()
	{
		return $this->hasOne(Shop::class, 'id', 'shop_id');
	}

	public function balanceOrder()
	{
		return $this->hasOne('\iBrand\Shop\Core\Models\BalanceOrder', 'id', 'balance_order_id');
	}

	public function getImagesAttribute($value)
	{

		if (empty($value)) {

			return [];
		}

		return json_decode($value, true);
	}
}